<template>
  <div class="user-info-container">
    <el-card>
      <div id="userInfoBox" class="user-info-box">
        <!-- 标题 -->
        <h2 class="title">个人信息</h2>

        <div class="header">
          <!-- 头部渲染表格 -->
          <el-descriptions :column="2" border>
            <el-descriptions-item label="员工工号">
              {{ info.num }}
            </el-descriptions-item>
            <el-descriptions-item label="姓名">
              {{ info.name }}
            </el-descriptions-item>
            <el-descriptions-item label="出生日期">
              {{ info.birthday }}
            </el-descriptions-item>
            <el-descriptions-item label="身份证号">
              {{ info.idNum }}
            </el-descriptions-item>
            <el-descriptions-item label="部门">
              <el-text v-for="(item, index) in info.deptNames" :key="index">
                {{ item }}
                <br />
              </el-text>
            </el-descriptions-item>
            <el-descriptions-item label="岗位">
              <el-text v-for="(item, index) in info.postName" :key="index">
                {{ item }}
                <br />
              </el-text>
            </el-descriptions-item>
            <el-descriptions-item label="级别">
              {{ info.grade }}
            </el-descriptions-item>
            <el-descriptions-item label="邮箱地址">
              {{ info.email }}
            </el-descriptions-item>
            <el-descriptions-item label="联系电话1">
              {{ info.phoneNum1 }}
            </el-descriptions-item>
            <el-descriptions-item label="联系电话2">
              {{ info.phoneNum2 }}
            </el-descriptions-item>
          </el-descriptions>
        </div>
        <div class="body">
          <!-- 内容渲染表格 -->
          <el-descriptions direction="vertical" :column="1" border>
            <el-descriptions-item label="通信地址">
              {{ info.address }}
            </el-descriptions-item>
          </el-descriptions>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "accountDetail",
};
</script>
<script setup>
import { onMounted, ref } from "vue";
import { getEmpsByNumOrName } from "@/service/api/user";
import store from "@/store";

const info = ref({
  num: "",
  name: "",
  grade: "",
  phoneNum1: "",
  phoneNum2: "",
  email: "",
  idNum: "",
  birthday: "",
  address: "",
  deptNames: [""],
  postName: [""],
});

onMounted(async () => {
  const data =
    (await getEmpsByNumOrName({ id: store.getters.userInfo.id })) || [];
  if (data.length > 0) {
    info.value = data[0];
  } else {
    info.value = {
      num: "",
      name: "",
      grade: "",
      phoneNum1: "",
      phoneNum2: "",
      email: "",
      idNum: "",
      birthday: "",
      address: "",
      deptNames: [""],
      postName: [""],
    };
  }
});
</script>
<style lang="scss" scoped>
.print-box {
  margin-bottom: 20px;
  text-align: right;
}
.user-info-box {
  width: 1024px;
  margin: 0 auto;
  .title {
    text-align: center;
    margin-bottom: 18px;
  }
  .header {
    display: flex;
    ::v-deep .el-descriptions {
      flex-grow: 1;
    }
    .avatar {
      font-size: 222px;
      box-sizing: border-box;
      padding: 15px;
      border: 1px solid #ebeef5;
      border-left: none;
    }
    .remark {
      margin-right: 12px;
    }
  }
  .body {
    ul {
      list-style: none;
      li {
        span {
          margin-right: 62px;
        }
      }
    }
  }
  .foot {
    margin-top: 42px;
    text-align: right;
  }
}
</style>
